package com.aurora_manito.xiaomi.service.impl;

import com.aurora_manito.xiaomi.entity.Order;
import com.aurora_manito.xiaomi.entity.Orderdetail;
import com.aurora_manito.xiaomi.mapper.CartMapper;
import com.aurora_manito.xiaomi.mapper.OrderMapper;
import com.aurora_manito.xiaomi.mapper.OrderdetailMapper;
import com.aurora_manito.xiaomi.service.CartService;
import com.aurora_manito.xiaomi.service.OrderService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Aurora_Manito
 * @since 2020-05-27
 */
@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements OrderService {

    @Autowired
    OrderMapper orderMapper;
    @Autowired
    OrderdetailMapper orderdetailMapper;
    @Autowired
    CartMapper cartMapper;
    @Transactional
    @Override
    public int saveOrder(List<Orderdetail> orderdetailList, Order order) {
        //向订单表添加订单
        int insert = orderMapper.insert(order);
        System.out.println(order);
        //向订单详情表添加数据
        for (Orderdetail orderdetail : orderdetailList) {
            orderdetailMapper.insert(orderdetail);
        }
        //4.晴空购物车、
        Map<String,Object> conditions=new HashMap<>();
        conditions.put("userid",order.getUid());
       int mun=cartMapper.deleteByMap(conditions);

        return 1;
    }
}
